package b2.widget.fort
{
	import b2.config.*;
	import b2.net.*;
	import b2.scene.*;
	import b2.util.*;
	import b2.widget.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.ui.Mouse;

	public class RoundCampItem extends Sprite
	{
		//战役索引
		private var campIndex:int;
		//鼠标悬浮信息
		private var itemTip:BasicMessage;
		
		public function RoundCampItem(round:int, campIndex:int)
		{
			super();
			this.campIndex = campIndex;
			var campConfig:CampConfig = Config.campConfigs[campIndex];
			var enemies:Array = campConfig.getEnemy();
			var enemyConfig:EnemyConfig = Config.enemyConfigs[enemies[0][0]];
			var tankConfig:TankConfig = Config.objectConfigs[enemyConfig.tankIndex];
			//加载空槽位
			var rrect:Sprite = new Sprite();
			rrect.graphics.lineStyle(2.5, 0x27AAE1);
			rrect.graphics.drawRoundRect(0, 0, 68, 68, 25, 25);
			rrect.filters = [new DropShadowFilter(2, 45, 0x000000, 1, 2, 2, 1, 1, false)];
			addChild(rrect);
			//图标
			var TankIcon:Class = ResourceHelper.getInstance().getClassByName(tankConfig.iconImage);
			var tankIcon:Sprite = new TankIcon();
			tankIcon.x = 7.5;
			tankIcon.y = 7.5;
			//齐天大圣
			if (enemyConfig.tankIndex == 10015)
			{
				tankIcon.width = 76;
				tankIcon.height = 85;
			}
			//死亡骑士
			else if (enemyConfig.tankIndex == 10020)
			{
				tankIcon.width = 66;
				tankIcon.height = 66;
			}
			else
			{
				tankIcon.width = 55;
				tankIcon.height = 55;
			}
			tankIcon.filters = [new ColorMatrixFilter(enemyConfig.filter)];
			addChild(tankIcon);
			//轮次
//			var roundText:TextField = new TextField();
//			roundText.selectable = false;
//			roundText.defaultTextFormat = new TextFormat("微软雅黑", 10, 0xAA0000, false, true);
//			roundText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
//			roundText.autoSize = TextFieldAutoSize.LEFT;
//			roundText.text = "第" + round + "轮 ";
//			roundText.x = 2;
//			roundText.y = 2;
//			addChild(roundText);
			//战役名字
			var tankTitle:TextField = new TextField();
			tankTitle.selectable = false;
			tankTitle.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000);
			tankTitle.autoSize = TextFieldAutoSize.LEFT;
			tankTitle.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			tankTitle.htmlText = "<i><font color='#00AA00'> " + round + "</font>. </i>" + campConfig.name;
			tankTitle.x = 32 - tankTitle.width / 2;
			tankTitle.y = 47;
			addChild(tankTitle);
			
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
//			if (itemTip == null)
//			{
//				var enemyConfig:EnemyConfig = Config.enemyConfigs[enemyIndex];
//				var globalPoint:Point = this.parent.localToGlobal(new Point(this.x, this.y));
//				itemTip = new BasicMessage(enemyConfig.description, BFont.roundRecColor, 0x000000, 200); 
//				itemTip.x = globalPoint.x + this.width;
//				itemTip.y = globalPoint.y;
//				if (itemTip.x + itemTip.width > BFont.stageWidth)
//					itemTip.x = globalPoint.x - itemTip.width;
//				SceneManager.getInstance().currentScene.addChild(itemTip);
//			}
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
//			if (itemTip != null && itemTip.parent != null)
//			{
//				itemTip.parent.removeChild(itemTip);
//				itemTip = null;
//			}
		}
		
	}
}